<!DOCTYPE html>
<html lang="en" class="app"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://rbac.rbacshiro.com"
>
<head>
    <meta th:replace="template/top"/>
    <link rel="stylesheet" href="js/select2/select2.css" type="text/css" cache="false" />
    <link rel="stylesheet" href="js/select2/theme.css" type="text/css" cache="false" />
</head>
<body>
<section class="vbox">
    <section>
        <section class="hbox stretch"> <!-- .aside -->
            <!-- /.aside -->
            <section id="content">
                <section class="vbox">
                    <section class="scrollable padder">
                        <div class="panel panel-default" id="form-wizard">
                            <div class="step-content">
                                <form>
                                    <div>
                                        <p>部门名称:</p>
                                        <input type="text" name="name" autocomplete="off" class="form-control" placeholder="请输入部门名称" autocomplete="off" data-validation="required" data-validation-error-msg="菜单名称不能为空">
                                    </div>
                                    <shiro:hasPermission values="RBAC_AUTHORITY_DEPARTMENT_USERS" logical="AND">
                                    <div class="form-group">
                                        <p>选择用户:</p>
                                        <select name="userUuid" id="select2-option" style="width: 100%" multiple="multiple"></select>
                                    </div>
                                    </shiro:hasPermission>
                                    <input type="hidden" name="pUuid" value="">
                                    <br />
                                    <button type="submit" class="btn btn-sm btn-primary">提交</button>
                                </form>
                            </div>
                        </div>
                    </section>
                </section>
            </section>
        </section>
    </section>
</section>
<script th:replace="template/js"></script>
<shiro:hasPermission values="RBAC_AUTHORITY_DEPARTMENT_ADD" logical="AND">
    <!-- select2 -->
    <script src="js/select2/select2.min.js" cache="false"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.3.26/jquery.form-validator.min.js"></script>
    <script>
        $('input[name="pUuid"]').val(parent.document.getElementById("uuid").value);
        $.validate();
        $('form').submit(function(){
            commonAjax({
                url :'department/add',
                data:$(this).serialize(),
                dataType:'json',
                type:'post',
                success:function(result){
                    if(result.success) {
                        parent.location.reload();
                    } else {
                        layer.msg(result.message);
                    }
                }
            });
            return false;
        });
    </script>
    <shiro:hasPermission values="RBAC_AUTHORITY_DEPARTMENT_USERS" logical="AND">
        <script>
            commonAjax({
                url:'department/users',
                dataType:'json',
                success:function(result){
                    var optList = [];
                    var list = result.data;
                    for(var  k in  list) {
                        var item = list[k];
                        optList.push('<option value="' + item.uuid + '">' + item.username + '</option>')
                    }
                    $('#select2-option').html(optList.join('')).select2();
                }
            });
        </script>
    </shiro:hasPermission>
</shiro:hasPermission>
</body>
</html>